#pragma once
#include "EngineHead.h"
#include "ResourceBase.h"
#include "GPUBuffer.h"
#include "FoundationStruct.h"
#include "BoundBox.h"


namespace mini
{
	class CMesh : public CResourceBase
	{
		friend class CSkinMeshUnit;
		friend class CMeshUnit;
		friend class CResourceManager;
	public:
		CMesh();
		virtual ~CMesh();
		virtual bool initialise() override;

		CGPUBuffer* getVertexBuffer();
		CGPUBuffer* getIndexBuffer();
		void fillVertexBuffer(void* pData, size_t length, UINT8 typeSize, int memoryType = D3D11_USAGE_DEFAULT);
		void fillIndexBuffer(void* pData, size_t length, UINT8 typeSize, int memoryType = D3D11_USAGE_IMMUTABLE);
		std::string getName() const;
		void setName(const std::string name);
		UINT32 getIndiceCount();
		UINT32 getVerticeCount();
		UINT32 getIndexbufferType();

	//private:
#ifdef WIN32
		VertexFormatVTNTB* getVertices();
		VertexFormatVTNTBSkin* getVerticesSkin();
#else
		VertexFormatVTN* getVertices();
#endif // WIN32
		UINT32* getIndices();
		UINT32 getFaceNumber();
		UINT32 getVerticesCount();
		class CSkeleton* getSkeleton();
		void setSkeleton(CSkeleton* pSkeleton);

	private:
		std::vector<std::list<UINT32> >		mSkinInfo;

#ifdef WIN32
		std::vector<VertexVT>				mVerticesPT;
		std::vector<VertexFormatVC>			mVerticesPC;
		std::vector<VertexFormatVTNTB>		mVertices;
		std::vector<VertexFormatVTNT>		mVerticesT;
		std::vector<VertexFormatVTNTBSkin>	mVerticesSkin;
		byte* mpDataStream = nullptr;
#else
		std::vector<VertexFormatVTN>		mVertices;
		std::vector<VertexFormatVTNSkin>	mVerticesSkin;
#endif
		std::vector<UINT32> mIndices;
		CGPUBuffer*	mpVertexBuffer = nullptr;
		CGPUBuffer*	mpIndexBuffer = nullptr;
		CSkeleton*	mpSkeleton = nullptr;
		CBoundBox	mBoundBox;
		UINT32 mVertexCount;
		UINT32 mIndexCount;
		UINT32 mVertexTypeSize;
		int mIndeiceType = DXGI_FORMAT_R32_UINT;
		std::string mStrName;
	};
}
